package com.xjm.ips.controller.personnel;

import com.xjm.ips.entity.*;
import com.xjm.ips.service.EmployeeBasiService;
import com.xjm.ips.service.PersonnelEcService;
import com.xjm.ips.service.RewardOrPenaltyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/personnel/ec")
public class PersonnelEcController {
    @Autowired
    PersonnelEcService personnelEcService;
    @Autowired
    EmployeeBasiService employeeBasiService;
    @Autowired
    RewardOrPenaltyService rewardOrPenaltyService;
    /**
     * 分页查询员工资料，传页数和条数，不传则默认第一页10条
     */
    @GetMapping("/")
    public MyPage getEmployeeEc(@RequestParam(defaultValue = "1") Integer pageNo,
                                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                              Employeeec employeeec){
        return personnelEcService.getEmployeeEc(pageNo,pageSize,employeeec);
    }

    @PostMapping("/searchemployeeec")
    public MyPage getEmployeeEcByParams(@RequestParam(defaultValue = "1") Integer pageNo,
                                @RequestParam(defaultValue = "10") Integer pageSize,
                                @RequestBody(required = false) Employeeec employeeec){
        return personnelEcService.getEmployeeEc(pageNo,pageSize,employeeec);
    }

    @GetMapping("/{jobNo}")
    public List<Employee> getEmployeeByWorkID(@PathVariable String jobNo){
        Employee employee = new Employee();
        employee.setJobNo(jobNo);
        List<Employee> employeeList = ((List<Employee>) employeeBasiService.getEmployee
                (1, 10, employee).getData());
        return employeeList;
    }

    @GetMapping("/getallrps")
    public List<RewardOrPenalty> getRewardOrPenalties(){
        return rewardOrPenaltyService.getRewardsOrPenalties();
    }

    @GetMapping("/getEmpByJobNo/{jobNo}")
    public Employee getEmpByJobNo(@PathVariable String jobNo){
         return employeeBasiService.getEmpByJobNo(jobNo);
    }

    @PostMapping("/")
    public AjaxJson addEmployeeEc(@RequestBody Employeeec employeeec){
        if(personnelEcService.addEmployeeEc(employeeec)==1){
            return AjaxJson.ok("添加员工奖惩信息成功!");
        }
        return AjaxJson.error("添加员工奖惩信息失败");
    }

    @PutMapping("/")
    public AjaxJson updateEmpolyeeEc(@RequestBody Employeeec employeeec){
        if(personnelEcService.updateEmpolyeeEc(employeeec)==1){
            return AjaxJson.ok("更新员工奖惩信息成功!");
        }
        return AjaxJson.error("更新员工奖惩信息失败!");
    }

    @DeleteMapping("/{id}")
    public AjaxJson deleteEmployeeEc(@PathVariable Integer id){
        if(personnelEcService.deleteEmployeeEc(id)==1){
            return AjaxJson.ok("删除员工奖惩信息成功！");
        }
        return AjaxJson.error("删除员工奖惩信息失败!");
    }
}
